<table width="100%" class="tblSort" border="1" cellspacing="0" rules="all" cellpadding="0">
<thead>
  <tr>
    <th>Operaci&oacute;n</th>
    <th>F.Proceso</th>
    <th>F.Documento</th>
    <th>Documento</th>
    <th>Usuario</th>
    <th>Referencia</th>
  </tr>
  </thead>
  <tbody>
  <?php

include('../../Connections/KRAPPERCON.php');
$fini = getVal('t_kx_fini');
$ffin = getVal('t_kx_ffin');
$clase = getVal('cbo_kx_clase');
$ref = getVal('referencia');
$user = getVal('t_usmov');
$and = '';

$tot_qt = 0;

$wh_cod = '';
$wh_alm = '';
$wh_fini1 = '';
$wh_fini2 = '';
$wh_ffin1 = '';
$wh_ffin2 = '';
$wh_fini3 = '';
$wh_ffin3 = '';
$wh_clad = '';
$wh_ref = '';

$wh_clad = isNull($clase,$and. " a.ClaDocID = '".$clase."'");

if (!isEmpty($wh_clad)) $and = ' and ';
$wh_ref = isNull($ref,$and." a.MovimientoRef = '".$ref."'");

if (isEmpty($ffin)) {
	if (!isEmpty($wh_alm.$wh_cod)) $and = ' and ';	
	$wh_fini1 = isZeros($fini,$and." date(a.MovimientoFec) = '".$fini."'");
	/* $wh_fini3 = isZeros($alm," a. = ".$alm); */
	}
else {
	if (!isEmpty($wh_cod.$wh_alm)) $and = ' and ';	
	
	$wh_fini1 = isZeros($fini,$and." date(a.MovimientoFec) >= '".$fini."'");

	
	if (!isEmpty($wh_fini1.$wh_cod.$wh_alm)) $and = ' and ';
	
	$wh_ffin1 = isZeros($ffin,$and." date(a.MovimientoFec) <= '".$ffin."'");
	
}
$where = '';
//$wcladoc = ' ';


if (!isEmpty($wh_cod . $wh_alm . $wh_fini1 . $wh_ffin1. $wh_clad. $wh_ref)) 
$where = ' where ';

$sql_prev = "select a.ClaDocID,b.ClaDocNom,b.ClaDocSig,a.MovimientoFec as feccre, a.MovimientoFeD  as fecdoc,a.MovimientoID docum,a.MovimientoTxt texto, a.MovimientoRef ref,a.UserID usuario from tt_movimiento as a left join tt_clasedoc b on b.ClaDocID = a.ClaDocID ";

$sql = $sql_prev. $where .$wh_clad. $wh_ref. $wh_fini1 . $wh_ffin1 ;
/*
$sql_in = "select a.FactCompFeCr as feccre,a.FactCompFeFc as fecdoc,a.FactCompID as docum,b.FactCompPos as posicion,FactCompTexto as texto,ArticuloID as articulo,AlmacenID AS almacen,FactCompQta as ctd,FactCompPrun as pru,FactCompNeto as neto,FacturaRef as ref from tt_facturacomp as a inner join tt_factcompdet as b on a.FactCompId = b.FactCompId ". $where . $wh_cod . $wh_alm . $wh_fini1 . $wh_ffin1 ;
 
$sql_ajus = "select a.MovimientoFec feccre, a.MovimientoFec fecdoc, a.MovimientoID docum,b.MovimientoPos as posicion,MovimientoTxt as  
texto , b.ArticuloID as articulo,b.AlmacenID almacen, MovimientoQty ctd, ArticuloCst pru,ArticuloCst*MovimientoQty neto,MovimientoRef ref
from tt_movimiento as a inner join tt_detmovimiento as b
on a.MovimientoID = b.MovimientoID " .$where. $wh_cod . $wh_alm . $wh_fini3 . $wh_ffin3 ;

$sql_out = "select FactFecCre as feccre,FactFecFac as fecdoc,a.FacturaId as docum,DetFacPos as posicion,' ' as texto,ArticuloID as articulo,AlmacenID as almacen,DetFacQty*-1 as ctd,cast(DetFactCst/DetFacQty as decimal(10,2))* -1 as pru,DetFactCst as neto,FactFolio as ref from vt_facturavta as a inner join tt_detfacturavta as b on a.FacturaID = b.FacturaID " .$where. $wh_cod . $wh_alm . $wh_fini2 . $wh_ffin2 ;
*/

//$sql = $sql.' order by feccre, articulo';

echo($sql);
//$sql = "call sp_queryKardex('".$codart."','".$alm."','".$fini."','".$ffin."',".$clase.")";
$res = $mysqli->query($sql) or die($mysqli->error.__LINE__);;

if($res){
	while($row = $res->fetch_assoc()){	
?>
  <tr class='<?php  if ($row['ClaDocSig']==1) echo 'clsIn'; else echo 'clsOut'; ?>'>
    <td><?php echo html_entity_decode($row['ClaDocNom']);?></td>
    <td><?php echo $row['feccre']; ?></td>
    <td><?php echo $row['fecdoc']; ?></td>
    <td  style="background-color:#FFFFFF;"><a href="#" onclick="goMov(this)"><?php echo $row['docum']; ?></a></td>
    <td><?php echo $row['usuario'];?></td>
    <td><?php echo $row['ref']; ?></td>
  </tr>
  <?php   		
	}	
	$res->close();
	
	$mysqli->check_result();
	
}
  ?>
  </tbody>
  <tfoot>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  </tfoot>
</table>
